Skip to contents

Wrapper for leaflet::leaflet for shorthand declaration of many map layout arguments. Automates many formatting options.

Usage

robomap(
  d,
  area,
  title = NULL,
  subtitle = "",
  caption = NULL,
  hovertext = list(flag = "", unit = ""),
  map_opacity = 0.9,
  tile_opacity = 0.7,
  map_palette = NULL,
  border_width = getOption("roboplot.trace.border")$width,
  legend_cap = 5,
  legend_position = "bottomright",
  data_contour = FALSE,
  markers = FALSE,
  log_colors = NULL,
  rounding = 1
)

Arguments

d

Data frame. Data to be created a table from.

area

Symbol, string, or function resulting in symbol or string. Variable from argument 'd' to use to identify the areas described by the map. This must be of class sfc_MULTIPOLYGON.

title, subtitle

Characters. Labels for plot elements. Optionally, use set_title() for the title if you want to omit the title from the displayed plot, but include it for any downloads through the modebar.

caption

Function or character. Use a string, or set_caption().

hovertext

List. Use a list with named items flag and unit.

map_opacity, tile_opacity

Double. Value from 0 to 1, defining how opaque the map polygon fill color or underlying map tiles are. 0 removes the tile layer, but retains the polygon borders if any.

map_palette

Character. Colors used for heatmap color range. Must be a hexadecimal color strings or a valid css color strings.

border_width

Integer. The width of polygon borders. Default is the trace border width set with set_roboplot_options().

legend_cap

Integer. The intended legend length. The actual length might vary.

legend_position

Character. Currently only accepts "bottom right" or NULL.

data_contour

Logical. Experimental. If TRUE, robomap() will produce a contour-like representation of the data, which does not conform to the boundaries of the polygons. This provides a smoother transition and helps in visualizing general trends across regions. Default is FALSE.

markers

Logical. Experimental. Whether markers will be added on the map based on the columns "lat" and "lon". Default is FALSE.

log_colors

Logical. Whether the colors scales is log or not.

rounding

Numeric. How robomap() rounds numeric values.

Value

A list of classes "leaflet" and "htmlwidget"

Examples

# You can use roboplotr::robomap() to create html maps. Note that very large
# number of map polygons makes for slow rendering maps.


# Currently robomap() only supports very little customization.
vaesto_postinumeroittain |>
  dplyr::filter(Alue == "Espoo") |>
  robomap(Postinumeroalue, title = "V\u00e4est\u00f6 Espoossa", caption = "Tilastokeskus")
# Default polygon colors are picked from trace colors set with # set_roboplot_options(), based on luminosity. Control polygon colors with # map_palette. robomap() expands upon this as necessary. vaesto_postinumeroittain |> robomap( Postinumeroalue, title = "V\u00e4est\u00f6 postinumeroittain", subtitle = "Otanta", caption = "Tilastokeskus", map_palette = c("lightgreen", "darkred") )
# robomap() automatically scales the values to differentiate large differences # in maximum and minimum values. Control this with log_colors vaesto_postinumeroittain |> robomap( Postinumeroalue, title = "V\u00e4est\u00f6 postinumeroittain", caption = "Tilastokeskus", map_palette = c("lightgreen", "darkred"), log_colors = FALSE )
# Control background tile opacity with 'tile_opacity', polygon opacity with # 'map_opacity' and borders with 'border_width'. vaesto_postinumeroittain |> robomap( Postinumeroalue, title = "V\u00e4est\u00f6 postinumeroittain", caption = "Tilastokeskus", map_palette = c("lightgreen", "darkred"), border_width = 2, tile_opacity = 0.2, map_opacity = 0.5 )
# Control the story you want to tell by giving an uneven palette. biased_palette <- colorRampPalette(c("lightgreen", "darkred"))(12)[c(1,3,5,7:12)] # This is how this biased palette looks like, more red colors than green. scales::show_col(biased_palette) # use the biased palette vaesto_postinumeroittain |> robomap( Postinumeroalue, title = "V\u00e4est\u00f6 postinumeroittain", caption = "Tilastokeskus", map_palette = biased_palette, map_opacity = 1, data_contour = TRUE, border_width = 0 )